package com.pagoda.nerp.trade.common.objectutil;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * Spring 配置文件获取工具类
 *
 * Created by Jungle on 2016/12/19.
 */
public class SpringConfigTool implements ApplicationContextAware {

    private static ApplicationContext applicationContext = null;
    private static SpringConfigTool springConfigTool = null;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        applicationContext = applicationContext;
    }

    public synchronized static SpringConfigTool init() {
        if (springConfigTool == null) {
            springConfigTool = new SpringConfigTool();
        }
        return springConfigTool;
    }

    public synchronized static Object getBean(String beanName) {
        return applicationContext.getBean(beanName);
    }

}
